home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1991 / number2 / shelldos.c < prev    next >
C/C++ Source or Header  |  1991-03-09  |  852b  |  36 lines

  1. /* shelldos.c -- function to execute DOS shell. */
  2. #define TESTING        /* comment if putting in library */
  3. #include <process.h>
  4. #include <stdlib.h>
  5. #include <errno.h>
  6.  
  7. int ShellToDOS (char *Prompt) {
  8.     char *Comspec = getenv ("COMSPEC");
  9.  
  10.     /* If no COMSPEC defined then report error and exit */
  11.     if (Comspec == NULL) {
  12.     errno = ENOENT;
  13.     return -1;
  14.     }
  15.  
  16.     if (putenv (Prompt)) {  /* Set the new PROMPT string */
  17.     errno = ENOMEM;
  18.     return -1;
  19.     }
  20.  
  21.     /* Attempt to start the command processor. */
  22.     return spawnl (P_WAIT, Comspec, NULL);
  23. }
  24.  
  25. #ifdef TESTING
  26. #include <stdio.h>
  27. /* The message to be displayed at the DOS prompt */
  28. static char *Message =
  29.     "PROMPT=Type EXIT to return to program $_$P$G";
  30.  
  31. void main (void) {
  32.     if (ShellToDOS (Message) == -1)
  33.     perror ("ERROR executing DOS shell");
  34. }
  35. #endif
  36.